package fm.dongman.modellib.local;

import android.content.Context;

import fm.dongman.animefm.contractlib.BaseDataSource;
import fm.dongman.animefm.contractlib.contract.SearchContract;
import fm.dongman.animefm.contractlib.model.SearchDataModel;

/**
 * Created by KUIGE on 2017/10/26.
 */

public class SearchLocalDataSource implements SearchContract.ISearchDataSource {

    private static SearchLocalDataSource SINGLETON;

    private DataOperationHelper mOperation;

    private SearchLocalDataSource(Context context)
    {
        mOperation = DataOperationHelper.getDataOperationHelper(context);
    }

    public static SearchLocalDataSource getInstance(Context context) {
        if (SINGLETON == null) {
            SINGLETON = new SearchLocalDataSource(context);
        }
        return SINGLETON;
    }

    @Override
    public void getData(BaseDataSource.LoadSourceCallback<? super SearchDataModel> callback) {
        callback.onDataLoaded(mOperation.downSearchHotWords());
    }

    @Override
    public void saveData(SearchDataModel dataModel) {
        mOperation.addSearchHotWords(dataModel);
    }

    @Override
    public void refreshData() {

    }



    @Override
    public void offLine() {

    }

    @Override
    public void clearHistorySearch(LoadSourceCallback<? super String> loadSourceCallback) {
        mOperation.deleteSearch();
    }
}
